

package com.ourteam.education.dao.impl ;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.beanutils.PropertyUtils;

import org.springframework.jdbc.core.RowMapper;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;


import com.ourteam.education.dao.Student;
import com.ourteam.education.dao.StudentDAOQueryBean;
import com.ourteam.education.dao.IStudentDAO;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2019-09-22 15:15:11
  * Warning ! This file will be overwrite when regenerate !
  * 
 */

public class AbstractStudentDAOJdbcImpl 
    extends AbstractSpringDAO implements IStudentDAO{
    
            
    	
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
		
		
	    
    					
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
    public static final String[] ENTITY_FIELDS = new String[] { Id,StudentName,StudentGender,ContactsPhone,ContactsRelation,Status,Remarks,StudentBirthday,ContactsName,DeleteFlag };
	
	public static final String[] ENTITY_PROPERTIES = new String[] {_DataObjectProperty.Id,_DataObjectProperty.StudentName,_DataObjectProperty.StudentGender,_DataObjectProperty.ContactsPhone,_DataObjectProperty.ContactsRelation,_DataObjectProperty.Status,_DataObjectProperty.Remarks,_DataObjectProperty.StudentBirthday,_DataObjectProperty.ContactsName,_DataObjectProperty.DeleteFlag};
	
	public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};
	
	private static String relatedJoinSQL = null;
	
	private static String basicFilterSQL = null;
	
	private DataAccessObjectHelper<Student, StudentDAOQueryBean> daoHelper;
	
	public AbstractStudentDAOJdbcImpl() {
		super();
		daoHelper = new DataAccessObjectHelper<Student, StudentDAOQueryBean>(this);
	}
	
	protected String getEntityName() {
		return EntityName;
	}

	protected String[] getEntityFields() {
		return ENTITY_FIELDS;
	}

	protected String[] getEntityProperties() {
		return ENTITY_PROPERTIES;
	}

	protected String[] getEntityPKFields() {
		return ENTITY_PK_FIELDS;
	}
	
	protected String[] getEntityAutoGenPKFields(){
		return ENTITY_AUTO_GEN_PK_FIELDS;
	}
	
	
	protected String[] getEntityUniqueFields() {
		return ENTITY_UNIQUE_FIELDS;
	}
	
	protected String getBaiscQueryFilter(){
	
		if(basicFilterSQL == null){
                        StringBuffer basicFilterSQLbuffer = new StringBuffer();
						
			basicFilterSQLbuffer.append(DeleteFlag).append("=  0  ");
			
						
						
			basicFilterSQL = basicFilterSQLbuffer.toString();
		}
		
		return basicFilterSQL;
	}
	
	protected String getRelatedJoinSQL(){
		
		if(relatedJoinSQL == null){
			StringBuffer relatedJoinSQLBuffer = new StringBuffer();
			
						
			relatedJoinSQL = relatedJoinSQLBuffer.toString();
		}
		
		return relatedJoinSQL;
	}
	
    /**
	 * Check Data Unique
	 * @param aStudent
	 * @throws Exception
	 */
	public boolean checkIsUnique(Student aStudent) throws Exception{
	
		if(aStudent == null){
			return true;
		}
	
		List valueList = new ArrayList();

		List pkValueList = new ArrayList();
		
		                
				
	    		
		pkValueList.add(aStudent.getId());
				
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
				
		return isUnique(valueList.toArray(new Object[valueList.size()]), pkValueList
				.toArray(new Object[pkValueList.size()]));
	
	}
	
	/**
	 * Insert Data
	 * @param aStudent
	 * @throws Exception
	 */
	public void insert(Student aStudent) throws Exception{
		
						
		PropertyUtils.setProperty(aStudent,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("0",int.class));
				
				
		super.doInsert(aStudent);

	}

    /**
	 * Batch Insert Datas
	 * @param aStudent
	 * @throws Exception
	 */
	public void batchInsert(Student[] aStudents) throws Exception{
		
		 super.doBatchInsert(aStudents);
		
	}

    /**
	 * Delete Data
	 * @param  final long id	 *
	 * @throws Exception
	 */
	public void delete( final long id ) throws Exception{

				
		Student tempStudent = findById( id);
		
						
		PropertyUtils.setProperty(tempStudent,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempStudent);
				
	}
	
	/**
	 * Delete Datas
	 * @param queryBean 
	 * @throws Exception
	 */
	public void delete(StudentDAOQueryBean queryBean) throws Exception{
	
				
		Student tempStudent = new Student();
		
				
				
	    PropertyUtils.setProperty(tempStudent,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempStudent,queryBean);
				
	}
	
	public void delete(Student aStudent) throws Exception {
				
				
									
						
					
				
		delete(aStudent.getId());
		
	}
	
	/**
	 * Update Data Selective
	 * @param aStudent
	 * @throws Exception
	 */
	public void update(Student aStudent) throws Exception{
		
						
											
				
				
		if(aStudent.getId() == 0){
			throw new Exception("Can not update object data whith out primary key value");
		}
				
		super.doUpdate(aStudent);
		
		Student tempObj = findById(aStudent.getId());
		
		if(tempObj != null){
			PropertyUtils.copyProperties(aStudent, tempObj);
		}
	}
	
	/**
	 * Batch Update Datas
	 * @param aStudents[]
	 * @throws Exception
	 */
	public void batchUpdate(Student[] aStudents) throws Exception{
		
		super.doBatchUpdate(aStudents);

	}

    /**
	 * Update Data By Condictions
	 * @param aStudent
	 * @param aValueCriteria 
	 * @param aTransaction
	 * @throws Exception
	 */
	public void update(Student aStudent, StudentDAOQueryBean aQueryBean) throws Exception{
		
				
		super.doUpdateByQuery(aStudent, aQueryBean);
		
	}
	
	/**
	 * Update Data By Condictions
	 * @param aQueryBean
	 * @throws Exception
	 */
	public void update(StudentDAOQueryBean aQueryBean) throws Exception {
		super.doUpdateByQuery(aQueryBean);
	}


    protected void checkNullValue(Student aStudent) throws Exception{	
																																									
		if(aStudent.getStudentBirthday() == null){
			throw new Exception("The Student.studentBirthday value is not allow NULL");
		}
													
		if(aStudent.getContactsName() == null){
			throw new Exception("The Student.contactsName value is not allow NULL");
		}
																
	}
	
	/**
	 * Get Data By ID
	 * @param  final long id	 * @return  ${businessObject.name}
	 * @throws Exception
	 */
	public Student findById( final long id) throws Exception{
		
		    	                
    	    	                		
		StudentDAOQueryBean queryBean = new StudentDAOQueryBean();
		
		StudentDAOQueryBean.Criteria  criteria = queryBean.createCriteria();
	
		                

		criteria.andIdEqualTo(id);
        
        
		//queryBean.setDistinct(true);
		
		Student[] Students = query(queryBean);
		
		if(Students.length == 0){
			return null;
		}
		else{
			return Students[0];
		}
		
	}

    /**
	 * Query Data
	 * @param queryBean
	 * @return Student[]
	 * @throws Exception
	 */
	public Student[] query(StudentDAOQueryBean queryBean) throws Exception{
				
		List result = super
				.doQuery(queryBean, new JdbcStudentRowMapper());

		return (Student[]) result.toArray(new Student[result.size()]);
	}
	
	/**
	 * Query ${businessObject.name} Selective
	 * @param queryBean
	 * @return Map[]
	 * @model
	 * @throws Exception
	 */
	public Map<String,Object>[] querySelective(StudentDAOQueryBean queryBean)  throws Exception{
		
		if(queryBean.getSelectProperties().isEmpty()){
			queryBean.addAllSelectProperties();
		}
		
		return super.doQuerySelective(queryBean);
		
	}
	
	/**
	 * Query Data Count
	 * @param queryBean
	 * @return int
	 * @throws Exception
	 */
	public int queryCount(StudentDAOQueryBean queryBean) throws Exception{
		
		return super.doQueryCount(queryBean);
		
	}
	
	public void synchronize(Student[] aStudents, StudentDAOQueryBean queryBean)
			throws Exception {
		daoHelper.synchronize(aStudents,queryBean);
		
	}

	public void synchronize(Student[] aStudents,
			StudentDAOQueryBean queryBean,
			net.dao.IDataAccessInterface.ISynchronizeCallback<Student> callBack)
			throws Exception {
		daoHelper.synchronize(aStudents,queryBean,callBack);
	}

    
     public static class JdbcStudentRowMapper implements
			RowMapper<Student> {

		public Student mapRow(ResultSet resultSet, int arg1) throws SQLException {
			Student object = new Student();

			int columnIndex = 1;
			
			int __dataType;
			
			try{
													
	            	            
				Object id = null;
				
								
				id =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdNull(resultSet.getBoolean(columnIndex++));
				
				if(id != null){
				
                    setBeanValue(object, _DataObjectProperty.Id,id);
				}
				
					
	            	            
				Object studentName = null;
				
								
				studentName =  resultSet.getObject(columnIndex++);
				
				               
				object.setStudentNameNull(resultSet.getBoolean(columnIndex++));
				
				if(studentName != null){
				
                    setBeanValue(object, _DataObjectProperty.StudentName,studentName);
				}
				
					
	            	            
				Object studentGender = null;
				
								
				studentGender =  resultSet.getObject(columnIndex++);
				
				               
				object.setStudentGenderNull(resultSet.getBoolean(columnIndex++));
				
				if(studentGender != null){
				
                    setBeanValue(object, _DataObjectProperty.StudentGender,studentGender);
				}
				
					
	            	            
				Object contactsPhone = null;
				
								
				contactsPhone =  resultSet.getObject(columnIndex++);
				
				               
				object.setContactsPhoneNull(resultSet.getBoolean(columnIndex++));
				
				if(contactsPhone != null){
				
                    setBeanValue(object, _DataObjectProperty.ContactsPhone,contactsPhone);
				}
				
					
	            	            
				Object contactsRelation = null;
				
								
				contactsRelation =  resultSet.getObject(columnIndex++);
				
				               
				object.setContactsRelationNull(resultSet.getBoolean(columnIndex++));
				
				if(contactsRelation != null){
				
                    setBeanValue(object, _DataObjectProperty.ContactsRelation,contactsRelation);
				}
				
					
	            	            
				Object status = null;
				
								
				status =  resultSet.getObject(columnIndex++);
				
				               
				object.setStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(status != null){
				
                    setBeanValue(object, _DataObjectProperty.Status,status);
				}
				
					
	            	            
				Object remarks = null;
				
								
				remarks =  resultSet.getObject(columnIndex++);
				
				               
				object.setRemarksNull(resultSet.getBoolean(columnIndex++));
				
				if(remarks != null){
				
                    setBeanValue(object, _DataObjectProperty.Remarks,remarks);
				}
				
					
	            	            
				Object studentBirthday = null;
				
								
				__dataType = resultSet.getMetaData().getColumnType(columnIndex);
				
				if(__dataType == java.sql.Types.DATE || __dataType == java.sql.Types.TIME || __dataType == java.sql.Types.TIMESTAMP){
					studentBirthday = resultSet.getTimestamp(columnIndex++);
				
				}
				else{
					studentBirthday =  resultSet.getObject(columnIndex++);
				
				}
				
				               
				object.setStudentBirthdayNull(resultSet.getBoolean(columnIndex++));
				
				if(studentBirthday != null){
				
                    setBeanValue(object, _DataObjectProperty.StudentBirthday,studentBirthday);
				}
				
					
	            	            
				Object contactsName = null;
				
								
				contactsName =  resultSet.getObject(columnIndex++);
				
				               
				object.setContactsNameNull(resultSet.getBoolean(columnIndex++));
				
				if(contactsName != null){
				
                    setBeanValue(object, _DataObjectProperty.ContactsName,contactsName);
				}
				
					
	            	            
				Object deleteFlag = null;
				
								
				deleteFlag =  resultSet.getObject(columnIndex++);
				
				               
				object.setDeleteFlagNull(resultSet.getBoolean(columnIndex++));
				
				if(deleteFlag != null){
				
                    setBeanValue(object, _DataObjectProperty.DeleteFlag,deleteFlag);
				}
				
								
								
				return object;
			}catch(Exception e){
				throw new SQLException(e.getMessage());
			}
		}

	}
	
}